fix(nextjs): Make request data available to tracesSampler for edge middleware root spans#22232
Conversation
chargome
left a comment
There was a problem hiding this comment.
Can we add one (unskipped) test case to verify the intent of this pr works correctly e2e in a non-cf scenario?
|
👋 @mydea, @nicohrubec — Please review this PR when you get a chance! |
37ad847 to
4c49615
Compare
|
👋 @mydea, @nicohrubec — Please review this PR when you get a chance! |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3cb9f98. Configure here.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

On the edge runtime, Next.js's OTel instrumentation creates and samples the
Middleware.executeroot span before the Sentry middleware wrapper runs. SonormalizedRequestwas never on the isolation scope at sampling time, and tracesSampler received undefined.This adds a
beforeSamplinghook in the edge SDK which populatesnormalizedRequest(method, URL, query string) based on HTTP span attributes. It also extends the edgespanStarthandler to fork the isolation scope forMiddleware.executeroot spans (similar to what #22013 did on the Node side after vercel/next.js#95357 made middleware a detached root span).The isolation-scope fork is extracted into a shared
maybeForkIsolationScopeForRootSpanutility used by both the Node and edge handlers.Fixes #22200